package vip.liux.contracts.models.notification;

import jakarta.persistence.*;
import lombok.Getter;
import lombok.Setter;
import vip.liux.contracts.shared.enums.SendStatus;
import vip.liux.contracts.shared.enums.messing.ChannelType;
import vip.liux.contracts.shared.enums.messing.Priority;
import vip.liux.contracts.shared.enums.messing.SendStrategy;
import vip.liux.domain.entities.auditing.CreationAuditedEntity;
import vip.liux.orm.jpa.converts.MapObjectConvert;

import java.time.LocalDateTime;
import java.util.Map;

/**
 * 通知消息发送任务实体类
 * 表示发送给用户的具体通知消息
 */
@Getter
@Setter
@Entity
@Table(name = "message_task")
public class MessageTask extends CreationAuditedEntity<Long> {

    /**
     * 模板编号
     */
    @Column(name = "template_code", nullable = false)
    private String templateCode;

    /**
     * 业务方自定义唯一消息流水号
     */
    @Column(name = "message_code")
    private String messageCode;

    /**
     * 消息参数, json
     */
    @Column(name = "params")
    @Convert(converter = MapObjectConvert.class)
    private Map<String, Object> params;

    /**
     * 通知渠道类型 0 - 站内消息 1 - 短信 2 - 邮件 3 - Webhooks
     *
     * @see ChannelType
     */
    @Column(name = "channel_type", nullable = false)
    private ChannelType channelType;

    /**
     * 优先级 0 - 最低 1 - 低于正常 2 - 正常 3 - 正常以上 4 - 最高
     *
     * @see Priority
     */
    @Column(name = "priority", nullable = false)
    @Enumerated(EnumType.ORDINAL)
    private Priority priority;

    /**
     * 优先级 0 - 立即 1 - 定时 2 - 延迟 3 - 循环
     *
     * @see SendStrategy
     */
    @Column(name = "send_strategy", nullable = false)
    @Enumerated(EnumType.ORDINAL)
    private SendStrategy sendStrategy;

    /**
     * 消息状态 0 - 未投递 1 - 成功 2 - 失败 3 - 回执
     *
     * @see SendStatus
     */
    @Column(name = "status")
    @Enumerated(EnumType.ORDINAL)
    private SendStatus status;

    /**
     * 调度时间
     */
    @Column(name = "schedule_time", nullable = false)
    private LocalDateTime scheduleTime;

    /**
     * 完成时间
     */
    @Column(name = "completed_time")
    private LocalDateTime completedTime;
}